package com.example.ymm.modules1.service.impl.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ymm.base.BaseServiceImpl;
import com.example.ymm.model.TableList;
import com.example.ymm.model.YmPageDto;
import com.example.ymm.modules1.entity.my.user.DbTestNote;
import com.example.ymm.modules1.mapper.my.user.DbTestNoteMapper;
import com.example.ymm.modules1.query.DbTestNoteQueryCriteria;
import com.example.ymm.modules1.service.user.DbTestNoteService;
import com.example.ymm.util.QueryHelpPlus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
public class DbTestNoteServiceImpl extends BaseServiceImpl<DbTestNoteMapper, DbTestNote> implements DbTestNoteService {

    @Override
    public TableList<DbTestNote> list(DbTestNoteQueryCriteria criteria, YmPageDto pageDto) {
        IPage<DbTestNote> page = new Page<DbTestNote>(pageDto.getPage(),pageDto.getPageSize());
        baseMapper.selectPage(page, QueryHelpPlus.getPredicate(DbTestNote.class, criteria));
        TableList<DbTestNote> tableList=new TableList(page);
        return tableList;
    }

    public List<DbTestNote> queryAll(DbTestNoteQueryCriteria criteria) {
        QueryWrapper predicate = QueryHelpPlus.getPredicate(DbTestNote.class, criteria);
        predicate.orderByDesc("create_time");
        List<DbTestNote> result =baseMapper.selectList(predicate);
        return result;
    }

    @Override
    public void addFn(DbTestNote note) {
        String userId = getUserId();
        String userName = getUserName();
        note.setUserId(userId);
        note.setUserName(userName);
        saveOrUpdate(note);
    }
}
